//
//  JWClockBottomView.m
//  test
//
//  Created by 朱圳 on 2018/3/21.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "JWClockBottomView.h"

@implementation JWClockBottomView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
-(void)createSubViews{
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    
    
    UITextView * text = [[UITextView alloc]init];
    text.layer.borderWidth = 1;
    text.layer.borderColor = [UIColor orangeColor].CGColor;
    text.editable = NO;
    [self.contentView addSubview:text];
    [text mas_makeConstraints:^(MASConstraintMaker *make) {
        [make.top.mas_equalTo(self.contentView.mas_top) setOffset:15];
        [make.left.mas_equalTo(self.contentView.mas_left) setOffset:10];
        [make.right.mas_equalTo(self.contentView.mas_right) setOffset:-15];
        make.size.height.mas_equalTo(80);
        
    }];
    
    UILabel *placeHolderLabel = [[UILabel alloc] init];
    placeHolderLabel.text = @"请填写自我学习情况(选填)";
    placeHolderLabel.numberOfLines = 0;
    placeHolderLabel.textColor = [UIColor lightGrayColor];
    [placeHolderLabel sizeToFit];
    [text addSubview:placeHolderLabel];
    // same font
    text.font = [UIFont systemFontOfSize:13.f];
    placeHolderLabel.font = [UIFont systemFontOfSize:13.f];
    [text setValue:placeHolderLabel forKey:@"_placeholderLabel"];
    
    self.text = text;
    
    UIButton *btn = [[UIButton alloc]init];
    [btn setTitle:@"确定查看" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    btn.backgroundColor = dominantColor;
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.contentView addSubview:btn];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(120, 30));
        [make.top.mas_equalTo(text.mas_bottom) setOffset:15];
    }];
    self.btn = btn;
    
    UILabel *label = [[UILabel alloc]init];
    [self.contentView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        
        [make.top.mas_equalTo(text.mas_bottom) setOffset:18];
        make.left.mas_equalTo(text.mas_left);
    }];
    label.text = @"作业";
    self.label = label;
    
    UIButton *clickBtn = [[UIButton alloc]init];
    [self.contentView addSubview:clickBtn];
    [clickBtn mas_makeConstraints:^(MASConstraintMaker *make) {

        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.left.mas_equalTo(label.mas_right).with.offset(5);
        [make.top.mas_equalTo(text.mas_bottom) setOffset:18];
        
    }];
    [clickBtn setImage:[UIImage imageNamed:@"stu-ka1"] forState:UIControlStateNormal];
    [clickBtn addTarget:self action:@selector(allSelected:) forControlEvents:UIControlEventTouchUpInside];
    self.clickBtn = clickBtn;
    
}

-(void)allSelected:(UIButton *)sender{
    
    _contentModel.isChecked =!_contentModel.isChecked;
    if (_contentModel.isChecked) {
        [self.clickBtn setImage:[UIImage imageNamed:@"stu-ka"] forState:UIControlStateNormal];
        
    }else{
        [self.clickBtn setImage:[UIImage imageNamed:@"stu-ka1"] forState:UIControlStateNormal];
    }
    if (_jwDelegate) {
        if ([_jwDelegate respondsToSelector:@selector(ZyBtn:withModel:)]) {
            [_jwDelegate ZyBtn:sender withModel:_contentModel];
        }
    }
}

-(void)click:(UIButton *)sender{

    if (_jwDelegate) {
        if ([_jwDelegate respondsToSelector:@selector(CheckBtn:)]) {
            [_jwDelegate CheckBtn:sender];
        }
    }
}

- (void)setContentModel:(ContentModel *)contentModel{
    _contentModel = contentModel;
    if (_contentModel.status) {
        [self.clickBtn setImage:[UIImage imageNamed:@"stu-ka"] forState:UIControlStateNormal];
    }else{
        [self.clickBtn setImage:[UIImage imageNamed:@"stu-ka1"] forState:UIControlStateNormal];
    }
}
@end


